﻿using System;
using System.IO;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;

namespace AppUnioeste
{
	[Activity (Label = "IHC2014", MainLauncher = true)]
	public class MainActivity : Activity
	{
		protected override void OnCreate (Bundle bundle)
		{
			base.OnCreate (bundle);

			// Set our view from the "main" layout resource
			SetContentView (Resource.Layout.Main);


			if (!Database.Exists ()) {//Se o banco nao existe
				//Le o asset do banco de dados
				StreamReader reader = new StreamReader (Assets.Open ("database_create.sql"));

				//Le o arquivo e retorna a sql, para entao criar o banco
				Database.CreateDatabase (reader.ReadToEnd ());

				Console.WriteLine ("Banco Criado");
			} else {
				//Conecta com o banco
				Database.OpenDatabase ();

				Console.WriteLine ("Banco Aberto");
			}



			Button info = FindViewById<Button> (Resource.Id.informacoesButton);
			Button cal = FindViewById<Button> (Resource.Id.calendarioButton);
			Button pal = FindViewById<Button> (Resource.Id.palestrantesButton);
			Button loc = FindViewById<Button> (Resource.Id.locaisButton);


			info.Click += (sender, e) =>{
				//info.Text = string.Format ("{0} clicks!", count++);
				StartActivity (typeof(Informacoes));
			};

			pal.Click += (sender, e) =>{
				//info.Text = string.Format ("{0} clicks!", count++);
				StartActivity (typeof(Palestrantes));
			};

			cal.Click += (sender, e) =>{
				//info.Text = string.Format ("{0} clicks!", count++);
				StartActivity (typeof(Calendario));
			};

			loc.Click += delegate {
				var geoUri = Android.Net.Uri.Parse ("geo:0,0?q=Avenida+Tancredo+Neves+6731+Porto+Belo+PR+Brasil");
				var mapIntent = new Intent (Intent.ActionView, geoUri);
				StartActivity (mapIntent);
			};
		}
	}
}


